<?php
/**
 * author: yunshu
 * create: 18/2/27
 * description:
 */

namespace app\api\controller\v1;

use app\common\service\Pay as PayService;
use app\api\controller\Base;
use app\common\service\WxPayCallback;
use app\common\validate\IdValidate;

class Pay extends Base
{
    protected $beforeActionList = [
        'checkExclusiveScope' => ['only' => 'getPreOrder'],
    ];

    /**
     * 微信预支付 官方文档: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1
     * @url api/:version/pay/pre_order
     * @http POST
     * @param int $id  订单id
     * @return array 发起微信支付所需要的参数 (https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=5)
     */
    public function getPreOrder($id)
    {
        (new IdValidate())->checkValidate();

        return (new PayService($id))->preOrder();
    }

    /**
     * 支付完成后处理 官方文档: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_7
     * @url api/:version/pay/notify
     * @http POST
     * @param string
     * @return string
     */
    public function receiveNotify()
    {
        $wxPayNotify = new WxPayCallback();
        $wxPayNotify->handle();
    }
}